﻿using System;
using System.Text;
using CodeConsult.Adafruit.BLE_UART;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace CodeConsult.Adafruit_BLE_UART_FEZSpiderTest
{
    public partial class Program
    {
        void ProgramStarted()
        {
            Debug.Print("Program Started");

            var socket = breakout.Socket;
            var config = new NordicRf8001Config()
            {
                SpiModule = SPI.SPI_module.SPI2,
                ReqInputPin = socket.CpuPins[4],
                ActOutputPin = socket.CpuPins[5],
                RdyOutputPin = socket.CpuPins[3],
                RstInputPin = socket.CpuPins[6],
                McuSpiBitOrder = BitOrder.Msb
            };

            var chip = new NordicRf8001(config);
            chip.WaitForSetupDone();
            chip.OnDataReceived += data =>
            {
                try
                {
                    var s = new string(Encoding.UTF8.GetChars(data));
                    chip.Write(data);
                    Debug.Print(s);
                }
                catch (Exception)
                {
                }
            };
        }
    }
}
